/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.PokemonEJB;


import java.util.List;
import javax.annotation.Resource;
import javax.ejb.EJB;
import javax.ejb.Local;
import javax.ejb.SessionContext;
import javax.ejb.Stateless;


/**
 *
 * @author Branislav Paulis
 */
@Stateless
@Local(value=TrainerServiceLocal.class)
public class TrainerServiceImpl implements TrainerServiceLocal {

    @EJB
    private TrainerDAOLocal trainerDAO;
    
    @Resource
    private SessionContext ctx;

    public void setTrainerDAO(TrainerDAOLocal trainerDAO)
    {
         this.trainerDAO = trainerDAO;
    }

    public Trainer addTrainer(Trainer trainer){
        try {
            trainerDAO.addTrainer(trainer);
            return trainer;
        } catch(Exception e){
            ctx.setRollbackOnly();
            return null;
        }
    }

    public Trainer getTrainer(Long id) {
        try {
            return trainerDAO.getTrainer(id);
        } catch(Exception e){
            ctx.setRollbackOnly();
            return null;
        }
    }
    
    public Trainer updateTrainer(Trainer trainer) {
        try {
            trainerDAO.updateTrainer(trainer);
            return trainer;
        } catch(Exception e){
            ctx.setRollbackOnly();
            return null;
        }
    }

    public Trainer removeTrainer(Trainer trainer) {
        try {
            trainerDAO.removeTrainer(trainer);
            return trainer;
        } catch(Exception e){
            ctx.setRollbackOnly();
            return null;
        }
    }

    public List<Trainer> getAllTrainers() {
        try {
            return trainerDAO.getAllTrainers();
        } catch(Exception e){
            ctx.setRollbackOnly();
            return null;
        }
    }
}